package cn.edu.stu.contorller;

import cn.edu.stu.bean.MicUser;
import cn.edu.stu.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Karl
 * @Date 2022/12/11 - 14:05
 */
@Controller
public class IndexController {

    @Autowired
    UserService userService;


    @GetMapping("/pageTest")
    @ResponseBody
    public PageInfo<MicUser> queryWithPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam(required = false,defaultValue = "5") Integer pageToShow){
        return userService.getUserWithPage(pageNum,pageSize,pageToShow);
    }

    @GetMapping({"/bg/login"})
    public String index(){

        return "login";
    }

    @GetMapping({"bg/index"})
    public String login(@CookieValue(value = "token" ,required = false)String token){
        return "index";
    }

    @GetMapping("/bg/logout")
    public String login(HttpServletResponse response){
        Cookie cookie = new Cookie("token", "");
        cookie.setMaxAge(0);
        cookie.setPath("/");
        response.addCookie(cookie);
        return "redirect:/";
    }






}
